<template>
  <div class="tabControl">
      <div v-for="(item,index) in titles" :key="index" 
      class="tabControlItem"
      :class="{active: index===currentIndex}"
      @click="itemClick(index)"
      >
          <span>{{item}}</span>
      </div>
      
  </div>
</template>

<script>
export default {
    name:'TabControl',
    props:{
        titles:{
            type:Array,
            default(){
                return []
            }
        }
    },
    data(){
        return{
            currentIndex:0
        }
    },
    methods:{
        itemClick(index){
            this.currentIndex =index
            this.$emit('tabClick',index)
        }
    }
}
</script>

<style lang='scss' scoped>
.tabControl{
    display: flex;
    text-align: center;
    font-size: 15px;
    height: 40px;
    line-height: 40px;
    background-color: #fff;
    .tabControlItem{
        flex: 1;
        span{
            padding: 5px;
        }
    }
    .active{
        color: rgb(217, 90, 126);
        span{
            border-bottom: 2px solid rgb(217, 90, 126);
        }
    }
}
</style>